<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="/commons/taglibs.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp" />
    <title>新增医师信息</title>
    <%@ include file="/commons/static.jsp"%>
    <link href="${ctx}/dep/css/fileinput.css" media="all" rel="stylesheet" type="text/css" />	
    <link href="${ctx}/dep/moban/css/beyond.min.css" rel="stylesheet" />
    <link href="${ctx}/dep/moban/css/typicons.min.css" rel="stylesheet" />
    <link href="${ctx}/dep/moban/css/animate.min.css" rel="stylesheet" />
    <link rel="stylesheet" href="${ctx}/dep/dist/css/dropify.css">
    <link rel="stylesheet" href="${ctx}/dep/zTreeStyle/zTreeStyle.min.css" />
</head>
<body>
           <div class="wrapper">
                <!-- 面包屑导航 -->
                <div class="page-breadcrumbs">
                    <ul class="breadcrumb">
                        <li>
                            <i class="fa fa-home"></i>
                            <a href="index.html">首页</a>
                        </li>
                        <li class="active">
                          <a href="#">医师信息管理</a>
                        </li>
                        <li class="active">
                          医师信息服务
                        </li>
                    </ul>
                </div>
                <!-- /面包屑导航-->
                 <div class="page-body">
                      <div class="row">
                        <div class="col-xs-12 col-md-12">
                            <div class="widget">
                                <div class="widget-body" style="overflow:hidden">
                                	<div class="col-lg-12 col-sm-12 col-xs-12 ">
                                        <div class="widget">
                                            <div class=" bancgud" >
                                            	 <div class="formfont">基础信息</div>
                                            	  <form class="form-horizontal form-bordered searchinfo col-xs-offset-1" method="post" name="doctorForm" id="doctorForm" onsubmit="return userformedit()">
                                            	  	<input type="hidden" id="method" value="${method }">
                                            	  	<input type="hidden" name="id" value="${doctor.id }">
                                                    <div class="form-group">
                                                        <label for="inputEmail3" class="col-sm-2 control-label no-padding-right">医师姓名<span class="help-inline"><font color="red">*</font> </span></label>
                                                        <div class="col-sm-7">
                                                            <input type="text" name="name" class="form-control zj-dd"  id="tt" placeholder="请输入医师姓名"value="${doctor.name }" disabled="disabled">
                                                        </div>
                                                    </div>
                                                    <div class="form-group ">
                                                        <label for="inputPassword3" class="col-sm-2 control-label no-padding-right">性&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;别</label>
                                                        <div class="radio">
                                                            <label >
                                                                <input name="sex" type="radio" disabled="disabled" value="1" ${doctor.sex=="1"?"checked='checked'":""}>
                                                                <span class="text">男 &nbsp;&nbsp;</span>
                                                            </label>
                                                            <label class="">
                                                                <input name="sex" type="radio" disabled="disabled" value="2" ${doctor.sex=="2"?"checked='checked'":""}>
                                                                <span class="text">女</span>
                                                            </label>
                                                            <label class="">
                                                                <input name="sex" type="radio" disabled="disabled" value="0" ${doctor.sex=="0"?"checked='checked'":""}>
                                                                <span class="text">其他</span>
                                                            </label>
                                                        </div>
                                                    </div>

                                                    <div class="form-group">
                                                        <label for="inputPassword3" class="col-sm-2 control-label no-padding-right">手&nbsp;&nbsp;&nbsp;机&nbsp;&nbsp;号</label>
                                                        <div  class="col-sm-7">
                                                            <input type="text" name="mobile" class="form-control fl "  placeholder="请输入手机号" value="${doctor.mobile }" disabled="disabled">
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right">医师职称</label>
                                                    	<div class="col-sm-7" >
		                                                    <select class="col-sm-12 form-control" name="profession">
		                                                        <option value="1" ${doctor.profession=="1"?"selected='selected'":""}>住院医师（助教）</option>
                                                                <option value="2" ${doctor.profession=="2"?"selected='selected'":""}>主治医师（讲师）</option>
                                                                <option value="3" ${doctor.profession=="3"?"selected='selected'":""}>副主任医师（副教授）</option>
                                                                <option value="4" ${doctor.profession=="4"?"selected='selected'":""}>主任医师（教授）</option>
		                                                    </select>
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label class="col-sm-2 control-label no-padding-right">是否免费</label>
                                                    	<div class="col-sm-7" >
		                                                    <select class="col-sm-12 form-control" name="isFree">
		                                                        <option value="1" ${doctor.isFree=="1"?"selected='selected'":""}>是</option>
                                                                <option value="0" ${doctor.isFree!="1"?"selected='selected'":""}>否</option>
		                                                    </select>
                                                        </div>
                                                    </div>
                                                    <div class="form-group">
                                                        <label for="inputPassword3" class="col-sm-2 control-label no-padding-right">医师职业类别</label>
                                                        <div class="checkbox">
                                                            <label >
                                                                <input name="type" type="radio" disabled="disabled" value="1" ${doctor.type=="1"?"checked='checked'":""}>
                                                                <span class="text" >临床</span>
                                                            </label>
                                                            <label class="">
                                                                <input name="type" type="radio" class="" disabled="disabled" value="2" ${doctor.type=="2"?"checked='checked'":""}>
                                                                <span class="text">中医</span>
                                                            </label>
                                                            <label class="">
                                                                <input name="type" type="radio" class="" disabled="disabled" value="3" ${doctor.type=="3"?"checked='checked'":""}>
                                                                <span class="text">中西医结合</span>
                                                            </label>
                                                            <label class="">
                                                                <input name="type" type="radio" class="" disabled="disabled" value="4" ${doctor.type=="4"?"checked='checked'":""}>
                                                                <span class="text">口腔</span>
                                                            </label>

                                                            <label class="">
                                                                <input name="type" type="radio" class="" disabled="disabled" value="5" ${doctor.type=="5"?"checked='checked'":""}>
                                                                <span class="text">公共卫生</span>
                                                            </label>
                                                        </div>
                                                    </div>
                                                    
                                                    <div class="form-group">
                                                        <label  class="col-sm-2 control-label no-padding-right">医师执照<span class="help-inline"><font color="red">*</font> </span></label>
                                                        <div class="col-sm-9">
                                                        <c:if test="${method==1 }">
	                                                          <c:forEach items="${doctor.paths}" var="url">
	                                                          	<c:if test="${url != null && url != ''}">
				                                                      <div class="box pull-left mr">
				                                                           <img src="${tracker_server }${url}">
				                                                      </div>
			                                                     </c:if>
			                                                </c:forEach>
                                                        </c:if>
                                                      <c:if test="${method==2 }">
	                                                      <c:set var="val" value="${fn:length(doctor.paths)}"/>
			                                                 <c:forEach items="${doctor.paths}" var="url" varStatus="vs">
															 	<c:if test="${url != null && url != ''}">
																	<div class="box pull-left mr">
																		<input type="file" class="dropify" data-default-file="${tracker_server}${url}" extra="cardImg" accept=".gif,.jpg,.jpeg,.png">
																	</div>
																</c:if>	
															</c:forEach>
															<c:forEach begin="${val}" end="4">
																<div class="box pull-left mr">
																	<input type="file" class="dropify" data-default-file="" extra="cardImg" accept=".gif,.jpg,.jpeg,.png">
																</div>
															</c:forEach>
                                                      </c:if>
		                                                </div>
		                                                
                                                    </div>
                                                    
                                                    <input type="hidden" name="physicianQualificationCertificate" value="${doctor.physicianQualificationCertificate }" style="display: none" id="urlpath">
                                                    
                                                    
                                                    <div class="form-group">
                                                        <label for="inputPassword3" class="col-sm-2 control-label no-padding-right">医师所属科室</label>
                                                        <div  class="col-sm-7">
                                                           <%-- <input type="text" class="form-control fl " name="department" placeholder="请输入所属单位" disabled="disabled" value="${doctor.department }"> --%>
                                                           <div class="input-group">
	                                                            <%-- <input value="${data.departmentId}" type="text" class="form-control" name="department" id="departmentId" style="display: none"> --%>
																<input value="${doctor.department}"  placeholder="请点击选择按钮" readonly="readonly" type="text" class="form-control" name="department" id="departmentName">
																<span class="input-group-btn">
																	<a href="javascript:selectDepart()" class="btn btn-default" type="button" style="line-height: 20px">选择</a>
																</span>
															</div>
                                                        </div>
                                                    </div>
                                                     <div class="form-group">
                                                        <label for="inputPassword3" class="col-sm-2 control-label no-padding-right">医师所属单位</label>
                                                        <div  class="col-sm-7">
                                                            <input type="text" class="form-control fl " name="hospital" placeholder="请输入所属单位" disabled="disabled" value="${doctor.hospital }">
                                                        </div>
                                                    </div>
                                                    <div class="form-group pad-butom">
                                                        <label for="inputPassword3" class="col-sm-2 control-label no-padding-right">医师描述</label>
                                                        <div  class="col-sm-7">
                                                             <textarea class="dc_text" name="description" disabled="disabled">${doctor.description }</textarea>
                                                        </div>
                                                    </div> 
                                                </div>
                                                <div class="col-xs-10  col-xs-offset-3 btn-bottm" style="padding-top:25px">
		                                            <button id="tagIdSubmitAddVip_btn" type="submit" class="btn btn-darkorange  col-sm-2 col-lg-offset-9 col-xs-offset-8" data-toggle="modal" onClick="history.go(-1)">确定</button>
		                                            <span id="quxiao" class="btn btn-active col-sm-2 col-lg-offset-1" data-toggle="modal" href="#" onClick="history.go(-1)">返回</span>
		                                       </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                         </div> 
                     </div>       
                  </div>          
                </div>
            </div>
         </div>   
    </div>
            <!-- /右侧内容 -->
</div>
<div class="modal fade in" aria-hidden="false" id="deparment">
			<div class="modal-dialog">
				<div class="modal-content">
					<div class="modal-header">
						<button class="close" type="button" data-dismiss="modal">×</button>
						<h4 class="modal-title">选择科室</h4>
					</div>
					<div class="modal-body form-horizontal">
						<form id="searchForm" onsubmit="return submitForm()">
							<div class="form-search">
								<label class="control-label col-lg-4">关键词：</label>
								<input id="keyWord" name="name" type="text" style="width: 200px;display: inline-block;">
								<div style="display: inline-block;margin-left: 10px;">
									<input type="submit" class="btn btn-primary" id="officesearch" value="搜索"/>
								</div>
							</div>
							<div class="area-select" style="margin-top: 20px">
								<ul id="departTree" class="ztree col-lg-offset-4"></ul>
							</div>
							<div class="hr-line-dashed"></div>
							<div class="form-group">
								<div class="col-sm-10 col-sm-offset-2">
									<span class="btn btn-darkorange col-sm-3" id="confirmButton">确定</span>
									<span class="btn btn-active col-sm-3 col-xs-offset-3" id="cancelButton">取消</span>
								</div>
							</div>
						</form>
					</div>
				</div>
			</div>
		</div>

<!--  <div class="modal fade in" id="closeCourse" aria-hidden="true">
    <div class="modal-dialog" >
        <div class="modal-content"  style="border-radius:50px!important" >
            
            <div class="modal-body form-horizontal" >
              <p class="text-warning">您的会员信息已提交成功</p>
            </div>
        </div>
    </div>
</div> -->
    <script src="${ctx}/dep/moban/js/bootstrap.min.js"></script>
    <script src="${ctx}/dep/moban/js/beyond.js"></script>
    <script src="${ctx}/dep/jquery.selectlist.js"></script>
    <script src="${ctx}/dep/moban/js/validation/bootstrapValidator.js"></script>
    <script type="text/javascript" src="${ctx}/dep/datetime/bootstrap-datepicker.js"></script>
    <script type="text/javascript" src="${ctx}/dep/datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
    <script src="${ctx}/dep/fileinput.js" type="text/javascript"></script>
    <script src="${ctx}/dep/fileinput_locale_zh.js" type="text/javascript"></script>
    <script src="${ctx}/dep/dist/js/dropify.js"></script>
    <script src="${ctx}/dep/zTreeStyle/jquery.ztree.all.min.js"></script>
    <script type="text/javascript">
      $(function(){
          $('.dropify').dropify({
              messages: {
                  'default': '点击或拖拽文件到这里',
                  'replace': '点击或拖拽文件到这里来替换文件',
                  'remove':  '移除文件',
                  'error':   '对不起，你上传的文件太大了'
              }
          });
    	  
        $("#doctorForm").bootstrapValidator();
      })
    </script>
   <script>
   $("#file-1").fileinput({
       uploadUrl: '#', 
       allowedFileExtensions : ['jpg', 'png','gif'],
       overwriteInitial: false,
       maxFileSize: 100,
       maxFilesNum: 10,
      
       slugCallback: function(filename) {
           return filename.replace('(', '_').replace(']', '_');
       }
	});
    $(function () {
     
        $("body").on("focus.page",".date-picker",function(){
            $(this).datetimepicker({
                format: "yyyy-mm-dd",
                minView:2,
                autoclose: true,
                language: "zh-CN"
            })
        });
        
      
        /* 新增 */
    // $('#tagIdSubmitAddVip_btn').on('click',function(){
    //     setTimeout(function(){
    //         $('#closeCourse').click();
    //     },1000);
    // });
 </script>
 <script>
	   
	    $("#file-1").fileinput({
	        uploadUrl: '#', 
	        allowedFileExtensions : ['jpg', 'png','gif'],
	        overwriteInitial: false,
	        maxFileSize: 100,
	        maxFilesNum: 10,
	       
	        slugCallback: function(filename) {
	            return filename.replace('(', '_').replace(']', '_');
	        }
		});
	     
	     $(function(){
				$('.abcselect').selectlist({
					zIndex: 1000,
					width: 400,
					height: 200
					
				});	
				var method = $("#method").val();
				if(method == 2){
					$("input").removeAttr("disabled");
					$("textarea").removeAttr("disabled");
					
				}
				if(method == 1){
					$("#tagIdSubmitAddVip_btn").hide();
					//$("#quxiao").attr("class","btn btn-darkorange  col-sm-2 col-lg-offset-9 col-xs-offset-8")
				}
			})
			//图片上传无限添加
			$(document).on('change', 'input.dropify', function() {			
				
				var inputName = $(this).attr('extra');			
				
				var str = '<div class="box pull-left mr"> <input type="file" extra="'+inputName+'" class="dropify" data-default-file="" accept=".gif,.jpg,.jpeg,.png"> </div>';
				
				var count = 0;
			 
				$('input.dropify[extra="'+inputName+'"]').each(function(){
					
					if($(this).parent('div').hasClass('has-preview')){
					
						count++ ;
					}
				
				})
				
				if(count>=4){
				
					$(this).parent().parent().parent().append(str).bind('click', function() {
					  $('.dropify').dropify({
						  messages: {
							  'default': '点击或拖拽文件到这里',
							  'replace': '点击或拖拽文件到这里来替换文件',
							  'remove':  '移除文件',
							  'error':   '对不起，你上传的文件太大了'
						  }
					  });
				    })
				  
				    $('.dropify').dropify({
							messages: {
							'default': '点击或拖拽文件到这里',
							'replace': '点击或拖拽文件到这里来替换文件',
							'remove':  '移除文件',
							'error':   '对不起，你上传的文件太大了'
				       }
					});
				
				}
							
			});
			
			 //文件上传
		    $('input.dropify').change(function(){
		    	
		    	
		    	var _this = $(this);
		    	
		        var formData = new FormData();  
		        
		        formData.append('uploadfile', $(this)[0].files[0]);
		        
		        var inputName = $(this).attr('extra');
		        
		        $.ajax({  
		            url: ctx + '/pic/uploadFile' ,  
		            type: 'POST',  
		            data: formData,  
		            async: false,  
		            cache: false,  
		            contentType: false,  
		            processData: false,
		            success: function (data) { 
		            	
		            	if(data.status == "success"){
		            		
		            		var index = _this.index('input[extra="'+inputName+'"]');
		            		
		            		var array = $('#urlpath').val().split(',');
		            		var arrayLength = array.length;
		            		console.info(arrayLength)
		            		console.info(index)
		            		var url = $("#urlpath").val();
		            		
		            		/* if(arrayLength != 0 && index < arrayLength){
		            			array[index] = data.path;
		            				
		            			for(var i=0; i<arrayLength; i++){
		            				if(i == arrayLength-1)
		            					url  = url + array[i];
		            				else
		            					url  = url + array[i] + ",";
		            			}
		            				
		            		}else{
			            		if(url != null && url != "")
			            			url += "," + data.path;
			            		else
			            			url = data.path;
			            		
		            		} */
		            		
		            		if(url == null || url == ''){
		            			url = data.path;
		            		}else if(index >= arrayLength){
		            			url += "," + data.path;
		            		}else{
		            			url = url.replace(array[index],data.path);
		            		}
		            		
		            		$("#urlpath").val(url);
		            		
		            	}else{	
		            		toastr.error("上传失败！");
		            	}
		            	
		            },
		            error: function(){
		            	toastr.error("系统错误");
		            }
		    	});
		    });
			function userformedit(){
				$('#doctorForm').data('bootstrapValidator').validate();
				if($('#doctorForm').data('bootstrapValidator').isValid()) {
					$.ajax({
						url : "${ctx}/doctor/updateDoc",
						type : "POST",
						data : $("#doctorForm").serialize(),
						dataType : "json",
						success : function(data) {
							if($(data)[0]["code"]=="1"){
								window.location.href = "${ctx}/doctor/index";
							}else{
								toastr.error($(data)[0]["msg"]);
							}
						}
					});
				}
			}
			
			//科室表单查询
		     function submitForm(){
		     	//加载科室树
		     	$.ajax({
		     		url : ctx + '/medical/getAllMedicalAndDepartment',
		     		data : $('#searchForm').serialize(),
		     		dataType : 'json',
		     		type : 'post',
		     		success : function(data){
		     			
		     			var zNodes =[];
		     			
		     			if(data.list != null){
		     				
		     				for(var i=0; i<data.list.length; i++){
		     					
		     					var subject = {};
		     					subject['id'] = data.list[i].id;
		     					subject['pId'] = 0;
		     					subject['name'] = data.list[i].institutionsName;
		     					subject['oid'] = data.list[i].id;
		     					
		     					zNodes.push(subject);
		     					
		     					if(data.list[i].depart != null){
		     						
		     						for(var j=0; j<data.list[i].depart.length; j++){
		     							var content = {};
		     							
		     							var id = data.list[i].depart[j].id;
		     							var name = data.list[i].depart[j].name;
		     							
		     							content['id'] = data.list[i].id + '' + id;
		     							content['pId'] = data.list[i].id;
		     							content['name'] = name;
		     							content['oid'] = id;
		     							content['click'] = "selectDepartment("+id+", '"+name+"')";
		     							zNodes.push(content);
		     						}
		     					}
		     				}
		     			}
		     			
		     			var setting = {
		     				check: {
		     					enable: false
		     				},
		     				data: {
		     					simpleData: {
		     						enable: true
		     					}
		     				}
		     			};
		     			
		     			//树加载
		     			$.fn.zTree.init($("#departTree"), setting, zNodes);
		     			var treeObj = $.fn.zTree.getZTreeObj("departTree");
		     			treeObj.expandAll(true);
		     			
		     		},
		     		error : function(){
		     			toastr.error('系统错误');
		     		}
		     	});
		     	
		     	return false;
		     	
		     }


		     function selectDepart(){
		     	
		     	//加载科室树
		     	$.ajax({
		     		url : ctx + '/medical/getAllMedicalAndDepartment',
		     		dataType : 'json',
		     		type : 'post',
		     		success : function(data){
		     			console.info(data)
		     			var zNodes =[];
		     			
		     			if(data.list != null){
		     				
		     				for(var i=0; i<data.list.length; i++){
		     					
		     					var subject = {};
		     					subject['id'] = data.list[i].id;
		     					subject['pId'] = 0;
		     					subject['name'] = data.list[i].institutionsName;
		     					subject['oid'] = data.list[i].id;
		     					
		     					zNodes.push(subject);
		     					
		     					if(data.list[i].depart != null){
		     						
		     						for(var j=0; j<data.list[i].depart.length; j++){
		     							var content = {};
		     							
		     							var id = data.list[i].depart[j].id;
		     							var name = data.list[i].depart[j].name;
		     							
		     							content['id'] = data.list[i].id + '' + id;
		     							content['pId'] = data.list[i].id;
		     							content['name'] = name;
		     							content['oid'] = id;
		     							content['click'] = "selectDepartment("+id+", '"+name+"')";
		     							zNodes.push(content);
		     						}
		     					}
		     				}
		     			}
		     			
		     			var setting = {
		     				check: {
		     					enable: false
		     				},
		     				data: {
		     					simpleData: {
		     						enable: true
		     					}
		     				}
		     			};
		     			
		     			//树加载
		     			$.fn.zTree.init($("#departTree"), setting, zNodes);
		     			var treeObj = $.fn.zTree.getZTreeObj("departTree");
		     			treeObj.expandAll(true);
		     			
		     /*			for(var i=0; i<zznode.length; i++){
		     				
		     				var checkedNode = treeObj.getNodeByParam("id", zznode[i].id, null);
		     				
		     				if(zznode[i].pId != null)
		     					treeObj.checkNode(checkedNode, true, true);
		     			}*/
		     			
		     		},
		     		error : function(){
		     			toastr.error('系统错误');
		     		}
		     	});
		     	
		     	$('#keyWord').val('');
		     	$('#deparment').modal('show');
		     	
		     }

		     function selectDepartment(id, name){
		     	
		     	$('#departmentName').val(name);
		     	/* $('#departmentId').val(id); */
		     	
		     	$('#deparment').modal('hide');
		     }
		</script>
   

</body>

</html>
